#!/bin/bash

BASENAME=$(basename $0)
CURDIR=$(echo $0 | sed "s/${BASENAME}//g")
source /home/burzum/Documents/Projects/keys-logs/env

CRONF=/etc/cron.d/get-cron

case ${1} in 
    "on"|"ON" )
	  echo "Turn ON"
	    echo "*/1 * * * * burzum $(realpath ${CURDIR}screen.sh ) & > /dev/null 2>&1" > /tmp/get-cron
	    echo "*/2 * * * * burzum $(realpath ${CURDIR}webshot.sh ) & > /dev/null 2>&1" >> /tmp/get-cron
	    sudo mv /tmp/get-cron ${CRONF}
	    exit
	;;
    "off"|"OFF" )
	  echo "Turn OFF"
	    sudo rm -f ${CRONF}
	    exit
	;;
	*)
	if [ -f ${CRONF} ];
	 then
	    echo "Turn OFF"
	    sudo rm -f ${CRONF}
	 else
	    echo "Turn ON"
	    echo "*/1 * * * * burzum $(realpath ${CURDIR}screen.sh ) & > /dev/null 2>&1" > /tmp/get-cron
	    echo "*/2 * * * * burzum $(realpath ${CURDIR}webshot.sh ) & > /dev/null 2>&1" >> /tmp/get-cron
	    sudo mv /tmp/get-cron ${CRONF}
	    sudo chown root.root ${CRONF}
	fi
	 exit
	;;
esac

exit 0